#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONPROOFSERVER_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONPROOFSERVER_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct AccountLogonProofServerData : public QSharedData
{
  quint32 status;
  quint8 serverProof[20];
  QByteArray additionalInfo;
};

class AccountLogonProofServer : public Message
{
public:
	static const int id = 0x54;
	BNCS_MESSAGE_SERVER_REGISTER(AccountLogonProofServer, id);

public:
	QSharedDataPointer<AccountLogonProofServerData> d;

public:
	AccountLogonProofServer()
	{
		d = new AccountLogonProofServerData();
	}
	
	virtual AccountLogonProofServer* create()
	{
		return new AccountLogonProofServer();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
	  return sizeof(d->status) + sizeof(d->serverProof) +
	    (d->additionalInfo.size() + 1);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> d->status;
		ds.readRawData((char*)d->serverProof, sizeof(d->serverProof));
		d->additionalInfo = (d->status == 0x0f) ? readStringFrom(ds) : "";

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds << d->status;
		ds.writeRawData((char*)d->serverProof, sizeof(d->serverproof));
		if (d->status == 0x0f)
		{
		  writeStringTo(ds, d->additionalInfo);
		}

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif /*NIXONBOT_CORE_BNCS_PROTOCOL_ACCOUNTLOGONCLIENT_H_*/
